<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <?= $show_code; ?>
        <title><?php echo $this->config->item('title_page'); ?></title>
    </head>
    <script>
        $(document).ready(function() {

            $('#btnBackPage').click(function() {
                parent.history.back();
                return false;
            });

            $('#cmbMainType').change(function() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>stock/add_stock/get_sub_type",
                    data: {id: $('#cmbMainType').val()},
                    dataType: "json",
                    success: function(data) {
                        $("#cmbSubType").find("option").remove();
                        $("#cmbBrand").find("option").remove();
                        if (data.length > 0) {
                            var opt = $('<option />');
                            opt.val("");
                            opt.text(data.list_model[""]);
                            $('#cmbSubType').append(opt);
                            var opt = $('<option />');
                            opt.val("");
                            opt.text(data.list_model[""]);
                            $('#cmbBrand').append(opt);
                            $.each(data.list_model, function(key, val) {
                                if (key !== "") {
                                    var opt = $('<option />');
                                    opt.val(key);
                                    opt.text(val);
                                    $('#cmbSubType').append(opt);
                                }
                            });
                        }
                    }
                });
            });
            $('#cmbSubType').change(function() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>stock/add_stock/get_brand",
                    data: {id: $('#cmbSubType').val()},
                    dataType: "json",
                    success: function(data) {
                        $("#cmbBrand").find("option").remove();
                        if (data.length > 0) {
                            var opt = $('<option />');
                            opt.val("");
                            opt.text(data.list_model[""]);
                            $('#cmbBrand').append(opt);
                            $.each(data.list_model, function(key, val) {
                                if (key !== "") {
                                    var opt = $('<option />');
                                    opt.val(key);
                                    opt.text(val);
                                    $('#cmbBrand').append(opt);
                                }
                            });
                        }
                    }
                });
            });
        });
    </script>
    <body>
        <div class="panel panel-default body-contain">
            <div class="panel-heading"><span class="icon-g-cargo"></span>
                <strong> การจัดการอะไหล่รถยนต์ (Auto Parts Management)</strong>
            </div>
            <div class="panel-body">
                <?php $this->load->view('contains/menu_module_bar'); ?>
                <div class="panel panel-default">
                    <div class="panel-heading"><span class="glyphicon glyphicon-file"></span>
                        <strong> เพิ่มข้อมูลอะไหล่รถยนต์</strong>
                    </div>
                    <?php echo form_open_multipart('stock/add_stock/validate', 'class="form-horizontal"  method="post"') ?>
                    <div class="panel-body">
                        <div class="pull-left col-xs-12 col-md-8">
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">รหัสอะไหล่</label>
                                    <div class="col-sm-9">
                                        <?= $txt_stock_code; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">ชื่ออะไหล่</label>
                                    <div class="col-sm-9">
                                        <?= $txt_stock_name; ?>
                                        <?= $err_stock_name; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">ประเภทหลัก</label>
                                    <div class="col-sm-5">
                                        <?= $cmb_main_type; ?>
                                        <?= $err_main_type; ?>
                                    </div>
                                </div>
                                <div id="div_subType" class="form-group">
                                    <label class="col-sm-3 control-label">ประเภทย่อย</label>
                                    <div class="col-sm-5">
                                        <?= $cmb_sub_type; ?>
                                        <?= $err_sub_type; ?>
                                    </div>
                                </div>
                                <div id="div_brand" class="form-group">
                                    <label class="col-sm-3 control-label">ยี่ห้อ</label>
                                    <div class="col-sm-5">
                                        <?= $cmb_brand; ?>
                                        <?= $err_brand; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">จำนวน</label>
                                    <div class="col-sm-4">
                                        <?= $txt_stock_qty; ?>
                                        <?= $err_stock_qty; ?>
                                    </div>
                                    <label class="col-sm-2 control-label">ชื่อสรรพนาม</label>
                                    <div class="col-sm-3">
                                        <?= $txt_stock_classifire; ?>
                                        <?= $err_stock_classifire; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">ราคา</label>
                                    <div class="col-sm-9">
                                        <div class="input-group">
                                            <?= $txt_stock_price; ?>
                                            <span class="input-group-addon">บาท</span>
                                        </div>
                                        <?= $err_stock_price; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">แจ้งคงเหลือต่ำกว่า</label>
                                    <div class="col-sm-9">
                                        <div class="input-group">
                                            <?= $txt_alert_below; ?>
                                            <span class="input-group-addon">ชิ้น</span>
                                        </div>
                                        <?= $err_alert_below; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">รายละเอียดเพิ่มเติม</label>
                                    <div class="col-sm-9">
                                        <?= $txt_stock_detail; ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-6">
                                        <button type="submit" class="btn btn-primary">บันทึกข้อมูล</button>
                                        <button id="btnBackPage" type="button" class="btn btn-default">ย้อนกลับ</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="pull-left col-xs-6 col-md-4">
                            <div class="panel panel-default">
                                <div class="panel-heading"><span class="glyphicon glyphicon-picture"></span>
                                    <strong> อัพโหดภาพถ่าย</strong>
                                </div>
                                <div class="panel-body">
                                    <div class="form-group">
                                        <?= $upload_pic; ?>
                                        <?php
                                        if (isset($err_upload)) {
                                            echo $err_upload;
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </body>
</html>
